﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Collections.ObjectModel;
using System.Reflection;
using System.CodeDom;

namespace ClassLibrary1
{
    public class UtenteSurrogate : IBusinessObjectSurrogate
    {
        public Type GetDataContractType(Type type)
        {
            if (type == typeof(Utente))
            {
                return typeof(UtenteReplacement);
            }
            else
            {
                return type;
            }
        }

        public object GetDeserializedObject(object obj, Type targetType)
        {
            if (obj is UtenteReplacement)
            {
                UtenteReplacement person = (UtenteReplacement)obj;
                return new Utente(person);
            }

            return obj;
        }

        public object GetObjectToSerialize(object obj, Type targetType)
        {
            if (obj is Utente)
            {
                Utente nsp = (Utente)obj;
                UtenteReplacement serializablePerson = new UtenteReplacement(nsp);
                return serializablePerson;
            }

            return obj;
        }

        public void GetKnownCustomDataTypes(Collection<Type> customDataTypes)
        {
            throw new NotSupportedException("unused");
        }

        public object GetCustomDataToExport(Type clrType, Type dataContractType)
        {
            throw new NotSupportedException("unused");
        }

        public object GetCustomDataToExport(MemberInfo memberInfo, Type dataContractType)
        {
            throw new NotSupportedException("unused");
        }

        public Type GetReferencedTypeOnImport(string typeName, string typeNamespace, object customData)
        {
            throw new NotSupportedException("unused");
        }

        public CodeTypeDeclaration ProcessImportedType(CodeTypeDeclaration typeDeclaration, CodeCompileUnit compileUnit)
        {
            throw new NotSupportedException("unused");
        }
    }
}
